clear
set more off
cap log close
set logtype text


/* NOTE: This file must be run on the NBER server */

global fullcount_files /homes/data/cens1940.work/olivetti/msjohn/dtafiles/output
global myfiles /homes/data/cens1940.work/olivetti/lsalisbu

log using $myfiles/simulation_prelim.txt, replace
use $myfiles/ALL_1pct.dta, clear

destring age, gen(test) force
replace test = 0 if age!="" & test==.
drop age
rename test age

gen name = upper(namefrst)

gen temp = 1 if marst=="Married"
replace temp = 3 if marst=="Separated"
replace temp = 4 if marst=="Divorced"
replace temp = 5 if marst=="Widowed" | marst=="Widow"
replace temp = 6 if marst=="Single"

tab marst if temp==.

drop marst
rename temp marst

label define mlbl 1 "Married" 3 "Separated" 4 "Divorced" 5 "Widowed" 6 "Never Married"
label values marst mlbl

keep if sex==2 & age>=30 & age<=45 & age>=30 & age<=45

count
tab marst

gen ever_married = marst!=6

keep name ever_married higrade samp1 samp2

tab higrade

gen educ_attain=8 if higrade=="Elementary school, 8th grade"
replace educ_attain=12 if higrade=="High School, 4th year"
replace educ_attain=10 if higrade=="High School, 2nd year"
replace educ_attain=7 if higrade=="Elementary school, 7th grade"
replace educ_attain=9 if higrade=="High School, 1st year"
replace educ_attain=6 if higrade=="Elementary school, 6th grade"
replace educ_attain=11 if higrade=="High School, 3rd year"
replace educ_attain=5 if higrade=="Elementary school, 5th grade"
replace educ_attain=16 if higrade=="College, 4th year"
replace educ_attain=4 if higrade=="Elementary school, 4th grade"
replace educ_attain=14 if higrade=="College, 2nd year"
replace educ_attain=13 if higrade=="College, 1st year"
replace educ_attain=3 if higrade=="Elementary school, 3rd grade"
replace educ_attain=0 if higrade=="None"
replace educ_attain=15 if higrade=="College, 3rd year"
replace educ_attain=2 if higrade=="Elementary school, 2nd grade"
replace educ_attain=17 if higrade=="College, 5th or subsequent year"
replace educ_attain=1 if higrade=="Elementary school, 1st grade"
replace educ_attain=0 if higrade=="0"
replace educ_attain=12 if higrade=="High School"
replace educ_attain=16 if higrade=="College"

tab educ_attain
count if educ_attain==.

drop higrade

xtile educ_qtile = educ_attain, nq(4)

save $myfiles/simulation_dataset_1.dta, replace

log close


